<template>
  <div style="max-height:840px;overflow-y:hidden;">
    <lay-form :model="model" ref="layFormRef" class="MainForm" >       
      
      
<lay-form-item label="名称" prop="name" >
<lay-input v-model="model.name" disabled></lay-input>
</lay-form-item>

<lay-form-item label="类型" prop="lx" >
<lay-input v-model="model.lx" disabled></lay-input>
</lay-form-item>

<lay-form-item label="排序号" prop="sortno" >
<lay-input v-model="model.sortno" disabled></lay-input>
</lay-form-item>


 



<lay-form-item label="备份Sql" prop="bkSql" >
<lay-textarea  v-model="model.bkSql" disabled></lay-textarea>
</lay-form-item>

<lay-form-item label="执行Sql" prop="runSql" >
<lay-textarea v-model="model.runSql" disabled></lay-textarea>
</lay-form-item>



<lay-form-item :label="model.p1Name" prop="p1Name" v-if="model.p1Name!=''" >
<lay-input v-model="model.p1"  ></lay-input>
</lay-form-item>


<lay-form-item :label="model.p2Name" prop="p2Name" v-if="model.p2Name!=''" >
<lay-input v-model="model.p2"  ></lay-input>
</lay-form-item>

<lay-form-item :label="model.p3Name" prop="p3Name" v-if="model.p3Name!=''" >
<lay-input v-model="model.p3"  ></lay-input>
</lay-form-item>

<lay-form-item :label="model.p4Name" prop="p4Name" v-if="model.p4Name!=''" >
<lay-input v-model="model.p4"  ></lay-input>
</lay-form-item>

<lay-form-item label="" >
    <lay-button size="lg" type="normal"
    @click="toRun"
    >执行</lay-button>


    <lay-button size="lg"  
    @click="toLog"
    style="margin-left:100px;"
    >日志</lay-button>

</lay-form-item>



    </lay-form>    
<Table  ref="tableComponent"   v-if="model.lx=='查询'"></Table>
  </div>

    
</template>

<script lang="ts">
import { ref, watch,reactive,onMounted,h } from 'vue'
import { layer } from '@layui/layer-vue'
import MyHttp from "../../library/MyHttp";  
import MyWin from "../../library/MyWin"; 
import MyPage from "../../library/MyPage"; 
import {MyExcel} from "../../library/MyExcel"; 
import {MySimpleExport,TableColumn} from "../../library/MySimpleExport"; 
import MyData from '../../library/MyData';

import {useUserStore} from "../../store/user";  
import MyAuth from "../../library/MyAuth";  
import MyClientData from '../../library/MyClientData';
import log from "./log.vue";  
import Table from "./table.vue";  


export default {
  props:{
      data:Object 
  },
  components:{  Table},
 setup(prop:any, context:any) {
  const baseUrl="/htsql";
  const myWin=ref<any>(null);
  const model = ref<any>( {
  
    } );
  const runModel = reactive<any>( {  id:"",
    p1:"",
    p2:"",
    p3:"",
    p4:""} )
    


  const layFormRef = ref<any>()     
  const detail=async (row:any)=>{
    let qm1={
         id:row.id
      }
      var r=await new MyHttp().post(baseUrl+"/detailitem",qm1,
        { 
        }
      );  
      model.value=r.data;
  }
  onMounted(() =>{  
    myWin.value=new MyWin();
     detail(prop.data);
  });
  const setData=(row:any)=>{
    detail(row);
  }
  const toRun=async()=>{
    let qm1={
         id:model.value.id,
         p1:model.value.p1,
         p2:model.value.p2,
         p3:model.value.p3,
         p4:model.value.p4,
      }
      var r=await new MyHttp().post(baseUrl+"/run",qm1,
        { 
        }
      );  
      if(model.value.lx=="查询"){
        (tableComponent.value as any).setData(r.data );
      }else{
        var msg=`操作完成，影响记录数${r.data}`;
        MyWin.alert(msg,{});
      }      
  }

  const toLog=(id:any)=>{
      var opt={
          title: '运行日志',
          content: h( log, 
            {  
             data:model.value.id,  
             onOk:(data:any)=>{
             
             }       
            }
            ), 
          w:1200,
          h:1000
        }; 
        myWin.value.open(opt ); 
    }
  
  const tableComponent=ref<any>();
  return {
    myWin,
    model,
    runModel,
    detail,
    setData,
    toRun,

    toLog,
     
    tableComponent
  }
}
}
</script>
